<template>
	<view>
		<view class="content" v-if="IsShowMain">
			<view class="swiperBox">
				<uni-swiper-dot :info="info" :current="current" field="content" :mode="mode" :dotsStyles="dotsStyles">
					<swiper class="swiper-box" autoplay="true" circular="true">
						<swiper-item v-for="(item ,index) in bannerlist" :key="index">
							<image @click="showImage" :src="item" mode="scaleToFill" style="width: 100%;height: 100%;"></image>
						</swiper-item>
					</swiper>
				</uni-swiper-dot>
			</view>
			<view class="newlist" v-if='showList'>
				<view class="bestnew">最新发布</view>
				<view class="itemList">
					<view @click="getdetails(item.id,index)" v-for="(item ,index) in joblist" :key="index">
						<view class="item">
							<view class="logo"><img :src="item.image" alt=""></view>
							<view class="info">
								<view class='title'> 
									<view class='gonzhong'>{{item.profession.title}}</view>
									<view class="xinzi">期望薪资：{{item.expect_pay}} 万韩元/天</view>
								</view>
								<view class='desc'>
									{{item.realname}} | {{item.gender}} | {{item.birthday}}岁 工作描述：{{item.work}}
								</view>
							</view>
						</view>
					</view>
				   <view v-if="IsNodate" class="nodate">
					   暂无更多数据
				   </view>
				</view>
			</view>
			<view class='tabbar'>
				<tabbar></tabbar>
			</view> 
		</view>
		
		<!-- 审核页面 -->
		<view v-if="IsChecked">
			<view class="swiperBox">
				<uni-swiper-dot :info="info" :current="current" field="content" :mode="mode" :dotsStyles="dotsStyles">
					<swiper class="swiper-box" autoplay="true" circular="true">
						<swiper-item v-for="(item ,index) in clist" :key="index">
							<image @click="showImageChecked" :src="item" mode="scaleToFill" style="width: 100%;height: 100%;"></image>
						</swiper-item>
					</swiper>
				</uni-swiper-dot>
			</view>
			<view class="ctitle">衣服新潮流</view>
			<view class='citemlist'>
				<view class='citem' @click="goBuy">
					<view style="margin: 0 40upx;">
						<image style="width: 280upx;height: 280upx;" src="https://qiuzhi.lalaluowang.club/sys/2.jpg"></image>
					</view>
					<view style="font-size: 28upx;">
						<view style="color:#666;">新潮儿童宝宝粉嫩装</view>
						<view>适合3~8周岁的儿童穿着</view>
						<view>尺码：均码</view>
						<view>材质：棉</view>
						<view style="color:red;">￥200.00</view>
					</view>
				</view>
				
				<view class='citem' @click="goBuy">
					<view style="margin: 0 40upx;">
						<image style="width: 280upx;height: 280upx;" src="https://qiuzhi.lalaluowang.club/sys/4.jpg"></image>
					</view>
					<view style="font-size: 28upx;">
						<view style="color:#666;">新潮儿童宝宝可爱装</view>
						<view>适合2~4周岁的儿童穿着</view>
						<view>尺码：均码</view>
						<view>材质：棉</view>
						<view style="color:red;">￥400.00</view>
					</view>
				</view>
				
				<view class='citem' @click="goBuy">
					<view style="margin: 0 40upx;">
						<image style="width: 280upx;height: 280upx;" src="https://qiuzhi.lalaluowang.club/sys/5.jpg"></image>
					</view>
					<view style="font-size: 28upx;">
						<view style="color:#666;">新潮儿童宝宝粉嫩装</view>
						<view>适合5周岁以上的儿童穿着</view>
						<view>尺码：均码</view>
						<view>材质：棉</view>
						<view style="color:red;">￥150.00</view>
					</view>
				</view>
				<view class='citem' @click="goBuy">
					<view style="margin: 0 40upx;">
						<image style="width: 280upx;height: 280upx;" src="https://qiuzhi.lalaluowang.club/sys/1.jpg"></image>
					</view>
					<view style="font-size: 28upx;">
						<view style="color:#666;">中老年女性装</view>
						<view>成年人装</view>
						<view>尺码：均码</view>
						<view>材质：棉</view>
						<view style="color:red;">￥450.00</view>
					</view>
				</view>
				<view class='citem' @click="goBuy">
					<view style="margin: 0 40upx;">
						<image style="width: 280upx;height: 280upx;" src="https://qiuzhi.lalaluowang.club/sys/6.jpg"></image>
					</view>
					<view style="font-size: 28upx;">
						<view style="color:#666;">新潮女装</view>
						<view>成年人装</view>
						<view>尺码：均码</view>
						<view>材质：丝绸</view>
						<view style="color:red;">￥350.00</view>
					</view>
				</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	import {uniSwiperDot} from "@/components/uni-swiper-dot/uni-swiper-dot.vue";
	import {tabbar} from "@/pages/tabbar/index.vue";
	import api from '@/pages/utils/api.js';
	export default {
		components: {
			uniSwiperDot,
			tabbar
		},
		data() {
			return {
				IsShowMain:false,
				IsChecked:false,
				IsNodate:false,
				showList:false,
				page:1,
				noRequest:false,
				bannerlist:[],
				joblist:[],
				
				clist:['https://qiuzhi.lalaluowang.club/sys/1.jpg','https://qiuzhi.lalaluowang.club/sys/2.jpg','https://qiuzhi.lalaluowang.club/sys/3.jpg']
			}
		},
		onLoad(option) {
		var vm = this;
		uni.setStorageSync('agentid', option.scene || ''); 
		uni.showLoading({
			title: '加载中'
		}); 
		//登录获取code换openid
		  wx.login({
			success (res) {
			  if (res.code) {
				api.getCode({
					code:res.code
				}).then(info=>{
					if(info.code == 1){
						uni.setStorageSync('token', info.data.openid);
						uni.setStorageSync('session_key', info.data.session_key);
						vm.getjoblist();
					}
				})
			  } else {
				console.log('登录失败！' + res.errMsg)
			  }
			}
		  });
		},
		onShow() {
			var vm = this;
			vm.getBanner();
			//vm.getjoblist();
			vm.getSys();
			
			//审核状态
			api.getChecked({
				
			}).then(data=>{
				if(data.code == 1){
					uni.hideLoading();
					uni.setStorageSync('checked_status', data.data.status);
					if(data.data.status != 1){
						vm.IsShowMain = true;
						vm.IsChecked = false;
					}else{
						vm.IsShowMain = false;
						vm.IsChecked = true;
					}
				}
			})
			
		},
		onUnload(){
			
		},
		methods: {
			//获取平台信息
			getSys:function(){
				var vm = this;
				api.getSys({
					
				}).then(data=>{
					if(data.code == 1){
						uni.setStorageSync('kefu', data.data.mobile);//客服电话
					}
				})
			},
			getBanner:function(){
				var vm = this;
				api.getBanner({
					
				}).then(data=>{
					if(data.code == 1){
						vm.bannerlist = data.data;
					}
				})
			},
			//图片预览
			showImage:function(){
				var vm = this;
				wx.previewImage({
				  current: vm.bannerlist[0], // 当前显示图片的http链接
				  urls: vm.bannerlist // 需要预览的图片http链接列表
				});
			},
			showImageChecked:function(){
				var vm = this;
				wx.previewImage({
				  current: vm.clist[0], // 当前显示图片的http链接
				  urls: vm.clist // 需要预览的图片http链接列表
				});
			},
			//获取求职列表
			getjoblist:function(){
				var vm = this;
				api.getJobList({
					page:vm.page,
					pagesize:8
				}).then(data=>{
					if(data.code == 1){
						uni.hideLoading();
						wx.hideLoading();
						vm.showList = true;
						var list = vm.joblist.concat(data.data)
						if(data.data.length == 0){
							vm.IsNodate = true;
							vm.noRequest = true;
							vm.page = 1;
						}else{
							vm.joblist = list;
						}
					}
				})
			},
			getdetails:function(id,index){ 
				uni.navigateTo({
					url: '/pages/index/details?id='+id
				});
			},
			//上拉加载
			onReachBottom:function(){
				var vm = this; 
				var page = vm.page;
				page++;
				vm.page = page;
				wx.showLoading({
					title: '玩命加载中',
				});
				if(vm.noRequest == false){
					vm.getjoblist();
				}else{
					wx.hideLoading();
				}
			},
			
			//审核
			goBuy:function(){
				var vm = this;
				wx.getSetting({
				  success (res){
					if (!res.authSetting['scope.userInfo']) {
					 uni.hideLoading();
					 uni.showModal({
					 	title: '系统提示',
						confirmText:'去授权',
					 	content: '需要授权才能购买哦',
					 	success: function (res) {
					 		if (res.confirm) {
					 		   uni.navigateTo({ 
					 			url: '/pages/auth/index'
					 		   });
					 		} else if (res.cancel) {
					 			uni.navigateBack({
					 				delta:1
					 			});
					 		}
					 	}
					 });
					}else{
						uni.showModal({
							 title: '友情提示',
							 showCancel: false,
							 content: '看中衣服？可以去官网购买送货上门哦',
							 success: function (res) {
								
							 }
						})
					}
				  }
				})
			}
		}
	}
</script>

<style>
.ctitle{
	border: 2upx #EEE dashed;
	color: red;
	font-size: 28upx;
	padding: 20upx;
	border:2upx #EEE dashed
}
	.citem{
		display: flex;
		align-items: center;
		line-height: 30px;
	}
	
/* .isview{
	background: #EEE;
	opacity: .6;
} */
.nodate{
	margin: 40upx auto 200upx auto;
	text-align: center;
	color:#777; 
	font-size: 28upx;
}
.bestnew{
	font-size: 27upx;
	padding:20upx;
	border-bottom: 1upx dashed #CCC;
}
.itemList{
	margin-bottom: 10%;
}
.itemList .item{
	display: flex;
	align-items: center;
	padding: 20upx;
	border-bottom: 1px solid #EDEDED;
}
.item .logo,.item .logo image{
	width: 90upx;
	height: 90upx;
	border-radius: 50%;
}
.item .logo{
	flex: 1;
}
.item .info{
	flex: 5;
}
.item .info .title{
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10upx 0;
	font-size: 28upx;
}
.item .info .desc{
	color:#B2B2B2;
	font-size: 28upx;
}
.tabbar{
	position: fixed;
	width: 100%;
	bottom: 0;
	background: #FFF;
}
.itemlist .home-title{
	color:#F7AE2B
}
</style>
